<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="send">Send</button>
    <button id="stopDiv">Stop</button>
    <script>
        const sendPromise = () => new Promise(function(resolve) {
            setTimeout(() => resolve(30), 10*1000)
        });
        const cancelPromise = function(p) {
            let obj = {};
            const innerPromise = new Promise(function(resolve, reject) {
                obj.resolve = resolve;
                obj.reject = reject;
            })

            obj.promise = Promise.race([innerPromise, p]);
            return obj
        }
        let cancel;

        send.onclick = ev => {
            const p = cancelPromise(sendPromise());
            cancel = p.resolve;
            console.log(p)
            p.promise.then(result => {
                console.log(result)
            })
        };

        stopDiv.onclick = ev => {
            cancel('拦截')
        }

    </script>
</body>
</html>